package cn.tedu.egmvc1.controller;

import cn.tedu.egmvc1.mapper.AddressMapper;
import cn.tedu.egmvc1.pojo.dto.InsertDTO;
import cn.tedu.egmvc1.pojo.entity.Address;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/address/")
public class AddressController {
    @Autowired
    private AddressMapper addressMapper;
    @RequestMapping("insert")
    public String insert(InsertDTO insertDTO){
        Address address = new Address();
        BeanUtils.copyProperties(insertDTO,address);
        int i = addressMapper.insert(address);
        return "添加成功,受影响的行数:"+i;
    }

    @RequestMapping("select")
    public List<Address> select(){
        return addressMapper.select();
    }

    @RequestMapping("delete")
    public String delete(int id){
        int i = addressMapper.delete(id);
        return "删除成功,受影响的行数:"+i;
    }

    @RequestMapping("update")
    public String update(Address address){
        int i = addressMapper.update(address);
        return "修改成功,受影响的行数:"+i;
    }
}
